package com.taxigang.server;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import com.google.appengine.api.datastore.Key;
import com.taxigang.shared.RouteInfo;
import com.taxigang.shared.TaxiCompanyInfo;

/**
 *
 * @author hall
 */
@Entity
@Table(name = "PARTNER")
public class Partner implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "PARTNERKEY", nullable = false)
	private Key key;
	@Column(name = NAME, nullable = true)
	private String name;
	@Column(name = CITY, nullable = true)
	private String city;
	@Column(name = ADDRESS, nullable = true)
	private String address;

	@Column(name = LAT, nullable = true)
	private Double lat;
	@Column(name = LNG, nullable = true)
	private Double lng;


	public static final  String NAME="NAME";
	public static final  String CITY="CITY";
	public static final  String ADDRESS="ADDRESS";
    public static final  String LAT="LAT";
    public static final  String LNG="LNG";


	public Partner() {
	}

	public long getId() {
		return key.getId();
	}

	public RouteInfo getInfo(){
		RouteInfo info =  new RouteInfo();
		info.setId(""+getId());
		info.setName(name);
		info.setDestination(address);
		info.setLat(lat);
		info.setLng(lng);
		return info;
	}


	public void setInfo(RouteInfo info){
		name =info.getName();
		address =info.getDestination();
		city ="";
		lat = info.getLat();
		lng = info.getLng();
	}


	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof Partner)) {
			return false;
		}
		Partner other = (Partner) object;
		if ((this.key == null && other.key != null) || (this.key != null && !this.key.equals(other.key))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "taxigangsystem.beans.Partner[partner=" + key.getId() + "]";
	}

}
